package com.me.mysqladmin.dao.impl;

import java.util.List;
import java.util.Map;

import javax.sql.RowSet;

import org.springframework.stereotype.Repository;

import com.me.mysqladmin.dao.SQLCommandDAO;
import com.me.mysqladmin.entity.SQLCommand;

@Repository("sqlCommandDAO")
public class SQLCommandDAOImpl extends BaseDAOImpl<SQLCommand> implements SQLCommandDAO {

	
	/**
	 * 执行SQL语句
	 */
	@SuppressWarnings("unchecked")
	@Override
	public SQLCommand executeSql(String sql) throws Exception{
		SQLCommand sqlCommand = new SQLCommand();
		Map<String, Object> map = executeAll(sql);
		sqlCommand.setType((String) map.get("type"));
		if(map.get("type").equals("query")){
			sqlCommand.setRs((List<Map<String, Object>>) map.get("data"));
		} else{
			sqlCommand.setLines((Integer) map.get("data"));
		}
		return sqlCommand;
	}
	
	@Override
	protected List<SQLCommand> toEntities(RowSet rs) {
		// TODO Auto-generated method stub
		return null;
	}

}
